<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use app\modules\Member\models\Member;
use dektrium\user\models\User;
use kartik\select2\Select2;
use yii\web\JsExpression;

$model->member_id = Yii::$app->user->identity->id;
?>

<div class="order-form">
    <?php $form = ActiveForm::begin([
                                 'options' => [],
                                 'layout' => 'horizontal',
                                 'fieldConfig' => [
                                    'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                                    'horizontalCssClasses' => [
                                        'label' => 'col-sm-3',
                                        'wrapper' => 'col-sm-8',
                                        'error' => '',
                                    ],
                                 ],
                            ]); ?>
    <?= $form->field($model, 'product_id')->label(false)->hiddenInput() ?>
    <?= $form->field($model, 'member_id')->label(false)->hiddenInput() ?>
	<div class="col-md-6">
    	<?= $form->field($model, 'source')->inline(true)->radioList(\Yii::$app->params['order_source']) ?>
		
		<?php /*
			$status  = \Yii::$app->params['order_status'];
			unset($status[4]);
			unset($status[10]);
			unset($status[11]);
			unset($status[12]);
		*/	?>
    	<!-- ?= $form->field($model, 'status')->inline(true)->radioList($status) ? -->

		<?php $merge  = [1=> '不需要', 2=> '需要']; ?>
    	<?= $form->field($model, 'is_merge')->inline(true)->radioList($merge) ?>

    	<?= $form->field($model, 'remark')->textArea(['rows' => 4, 'maxlength' => true]) ?>

    	<!-- ?= $form->field($model, 'username')->textInput(['maxlength' => 32]) ? -->
		<div class="form-group">
			<label class="control-label col-sm-3" for="order-username"><?= Yii::t('app.order', 'Username') ?></label>
			<div class="col-sm-8">
            <?= Select2::widget([
                    'name'  => 'Order[username]',
                    'attribute'  => 'username',
                    'options' => ['multiple' => false],
                    'pluginOptions' => array(
                        'placeholder' => Yii::t('app.order', 'Username'),
                        'allowClear' => true,
                        'tags' => true,
                        'minimumInputLength' => 1,
                        'ajax' => [
                                'url' => yii\helpers\Url::to(['/order/contact/suggest']),
                                'dataType' => 'json',
                                //'data' => new JsExpression('function(params) { return {q:params.term}; }')
                        ],
                    ),
					'pluginEvents' => [
        				"change" => "function(event){
        				    var name = event.target.value;
							// 获取联系人其它信息
							if(name){
								$.get('/order/contact/find-name', { name: name},
									function(data){
										if(data.company){
											$('#order-company').val(data.company);
										}
										if(data.phone){
											$('#order-phone').val(data.phone);
										}
								});
							}
        				}",
    				],
            ]) ?>
			</div>
		</div>
    	<?= $form->field($model, 'phone')->textInput(['maxlength' => 32]) ?>
    	<?= $form->field($model, 'company')->textInput(['maxlength' => 64]) ?>
    </div>

	<div class="col-md-6">

		<!-- 选择舱房 -->
    	<?php  echo $this->render('_change', ['model'=>$model, 'form'=>$form]); ?>
    </div>


    <div class="form-group col-md-12 text-center">
		<hr>
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

</script>
<?php app\components\JsBlock::end() ?>
